import { ApiProperty, IntersectionType } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsInt, IsNumber, IsOptional, IsString, Length } from 'class-validator';
import { PagerDto } from '~/common/dto/pager.dto';

export class FindTenantListDto extends IntersectionType(PagerDto) {
  @ApiProperty({ type: 'string', description: '租户名称', required: false })
  @IsString()
  @IsOptional()
  name: string;

  @ApiProperty({ type: 'string', description: '租户编码', required: false })
  @IsString()
  @IsOptional()
  code: string;

  @ApiProperty({ type: 'int', description: '租户状态 (0: inactive, 1: active)', required: false })
  @IsNumber()
  @Type(() => Number)
  @IsOptional()
  status: number;
}

// 通过继承的方式生成DTO
export class TenantCreateDto {
  @ApiProperty({ description: '租户名称', required: true })
  @IsString()
  @Length(1, 50, { message: '租户名称长度必须在1-50之间' })
  name: string;

  @ApiProperty({ description: '客服电话', default: '0551-3429804' })
  @IsString()
  @IsOptional()
  servicePhone: string;

  @ApiProperty({ description: '工作时间', default: '周一到周五10:00-18:00' })
  @IsString()
  @IsOptional()
  workTime: string;

  @ApiProperty({ description: '状态', default: true, required: false })
  @IsNumber()
  @Type(() => Number)
  @IsOptional()
  status?: number;

  @ApiProperty({ description: '租户地址' })
  @IsString()
  @IsOptional()
  address?: string;
}

export class TenantBindDto {
  @ApiProperty({ description: '租户ID', required: true, default: 0 })
  @IsInt()
  tenantId: number;

  @ApiProperty({ description: '用户ID', required: true, default: 0 })
  @IsInt()
  userId: number;
}
